package com.bprogram.Enum;

public enum YesOrNo {


    YES("Y","是"),
    NO("N","否");

    private String code;
    private String name;

    YesOrNo(String code, String name) {
        this.code = code;
        this.name = name;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    YesOrNo() {
    }

    /**
     * 通过code获取name
     * @param code
     * @return
     */
    public static String getName(String code){
        YesOrNo[] yesOrNos = values();
        for (YesOrNo yos :yesOrNos){
            if (yos.getCode().equals(code)){
                return yos.getName();
            }
        }
        return null;
}

    /**
     * 通过name获取code
     * @param name
     * @return
     */
    public static String getCode(String name){
        YesOrNo[] yesOrNos = values();
        for (YesOrNo yos :yesOrNos){
            if (yos.getName().equals(name)){
                return yos.getCode();
            }
        }
        return null;
    }


}
